﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" EnableViewState="false" %>

<%@ Register Src="controls/Messages.ascx" TagName="Messages" TagPrefix="uc2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <link type="text/css" rel="stylesheet" href="style.css" />

    <script language="javascript" type="text/javascript">
       function $(id)
       {
           return document.getElementById(id); 
       } 
       
       function AddMessage(nick, email, content, isPrivate)
       {
           $('txtContent').onblur(); 
       
           var validateOk = true;
           var validResult = ''; 
           if ($('emailValidator').style.visibility != 'hidden')
           {
                validResult += $('emailValidator').innerText + '\n';
                validateOk  = false;
           } 
           if ($('contentValidator').style.visibility != 'hidden')
           {
                validResult += $('contentValidator').innerText + '\n';
                validateOk  = false;
           } 
           if (!validateOk)
           {
               alert(validResult);
               return;
           }
           
           //callback & save to db & alert "add ok" & reload msgs
           var params = 'option=add&nick=' + escape(nick) + '&email=' + escape(email) + '&content=' + escape(content) + '&isPrivate=' + (isPrivate ? 'true' : 'false');
           $("msgContainer").innerHTML = "<div align=center>Saving new message...</div>";
           Ajax.Update('controls/Messages', 'msgContainer', params);
           $('txtContent').value='';
           $('txtEmail').value='';
           $('txtNick').value='';
       }
      
       function ResetPassword()
       {
           $('txtAdminPassword').value = ''; 
       } 
    </script>

</head>
<body style="overflow-x:hidden" onload="Ajax.OnPageLoad()">
    <form id="form1" runat="server">
        <!-- Header -->
        <div id="hdr">
            NBear Guestbook</div>
        <!-- left column -->
        <div id="lh-col">
            <h4>
                Leave Message</h4>
            <br />
            <div id="msgForm">
                <label for="txtNick">
                    Nick:</label>
                <input id="txtNick" type="text" maxlength="25" /><br />
                <label for="txtEmail">
                    Email:
                </label>
                <input id="txtEmail" type="text" maxlength="122" runat="server" /><br />
                <label for="txtContent">
                    Message:</label><br />
                <textarea id="txtContent" runat="server" onblur="this.value=this.value.replace(/^\s*/, '').replace(/\s*$/, '')"></textarea><br />
                <input id="checkPrivateMsg" type="checkbox" value="true" />
                <label for="checkPrivateMsg">
                    Private Message</label><br />
                <div>
                    <input id="btnAddMsg" type="button" value="Add Message" onclick="AddMessage($('txtNick').value, $('txtEmail').value, $('txtContent').value, $('checkPrivateMsg').checked);" /></div>
            </div>
        </div>
        <!-- end of left column -->
        <div id="validInfo">
            <asp:RegularExpressionValidator ID="emailValidator" runat="server" ControlToValidate="txtEmail"
                ErrorMessage="- Email format error!<br>" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" Font-Bold="True"></asp:RegularExpressionValidator><br />
            <asp:RequiredFieldValidator ID="contentValidator" runat="server" ErrorMessage="- Message Content Cannot be blank!<br>"
                Font-Bold="True" ControlToValidate="txtContent"></asp:RequiredFieldValidator></div>
        <!-- right column -->
        <div id="rh-col">
            <h2>
                Messages</h2>
            <div id="msgContainer">
                <uc2:Messages ID="Messages1" runat="server" />
            </div>
        </div>
        <!-- end of right column -->
        <div id="admin">
            <a href="#" onclick="if ($('adminLogin').style.display == 'none') $('adminLogin').style.display = 'inline'; else $('adminLogin').style.display = 'none';">Admin</a>
            <span id="adminLogin" style="display:none">-&gt; Password: <input type="password" id="txtAdminPassword" size="10" /> <input type="button" value="Login" onclick="Ajax.Update('controls/Messages', 'msgContainer', 'option=login&password='+escape($('txtAdminPassword').value)+'&pageNo='+$('curPage').innerHTML, 'ResetPassword')" /> <input type="button" value="Logout" onclick="Ajax.Update('controls/Messages', 'msgContainer', 'option=logout&pageNo='+$('curPage').innerHTML)"/></span>
        </div>
    </form>
</body>
</html>
